package com.fish.yssb.ui.page.activity.setPara;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AbsoluteLayout;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fish.yssb.R;
import com.fish.yssb.ui.page.activity.base.BaseActivity;
import com.fish.yssb.ui.page.util.TopToastUtil;
import com.fish.yssb.ui.page.widget.CustomDialog;
import com.jaeger.library.StatusBarUtil;


/**
 * A login screen that offers login via email/password.
 */
public class SetParaTwoActivity extends BaseActivity implements OnClickListener {
    private static final String TAG = SetParaListActivity.class.getSimpleName();


    EditText et_deveveid;
    EditText ed_msisdn;
    EditText et_ip;
    TextView tv_back, tv_save,et_cs,et_tcp,et_btl,et_sjw,et_tzw,et_zyfs,tv_set;
    private RelativeLayout ll_para_2, ll_para_3;
    private CustomDialog choosePicDialog;

    private int sevice_type,net_type;

    public static void start(Context context) {
        Intent intent = new Intent(context, SetParaTwoActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        sevice_type = -1;
        net_type = -1;
        StatusBarUtil.setTransparent(this);
        StatusBarUtil.setDarkMode(this);
        setContentView(R.layout.activity_setpara_two);
        initview();
        initData();
    }

    private void initData()
    {
        et_tcp.setText("蓝牙");
        et_btl.setText("9600");
        et_sjw.setText("7");
        et_tzw.setText("1");


    }


    //初始化视图
    @SuppressLint("WrongViewCast")
    private void initview() {
        //登录层、下拉层、其它登录方式层
        tv_back = findViewById(R.id.tv_back);
        tv_save = findViewById(R.id.tv_save);
        et_ip = findViewById(R.id.et_ip);
        ll_para_2 = findViewById(R.id.ll_para_2);
        ll_para_3 = findViewById(R.id.ll_para_3);
        et_tcp = findViewById(R.id.et_tcp);
        et_cs = findViewById(R.id.et_cs);
        et_zyfs = findViewById(R.id.et_zyfs);

        et_btl = findViewById(R.id.et_btl);
        et_sjw = findViewById(R.id.et_sjw);
        et_tzw = findViewById(R.id.et_tzw);

        tv_set = findViewById(R.id.tv_set);
        tv_set.setOnClickListener(this);
        ll_para_2.setOnClickListener(this);
        ll_para_3.setOnClickListener(this);
        tv_back.setOnClickListener(this);

    }

    private LinearLayout lyDlg;
    private TextView btn1, btn2,btn3, btnCancel;
    private Window window;

    @Override
    public void onClick(View view) {

        switch (view.getId()) {



            case R.id.ll_para_2:

                choosePicDialog = new CustomDialog(SetParaTwoActivity.this, true);
                choosePicDialog.setCustomView(R.layout.pic_select_dlg);

                 window = choosePicDialog.getDialog().getWindow();
                window.setGravity(Gravity.BOTTOM);
                window.setLayout(AbsoluteLayout.LayoutParams.MATCH_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT);

                lyDlg = (LinearLayout) choosePicDialog.findViewById(R.id.dialog_layout);
                lyDlg.setPadding(0, 0, 0, 0);

                btn1 = (TextView) choosePicDialog.findViewById(R.id.btn1);
                btn2 = (TextView) choosePicDialog.findViewById(R.id.btn2);
                btn3 = (TextView) choosePicDialog.findViewById(R.id.btn3);
                btn1.setText("串口");
                btn2.setText("红外");
                btn3.setText("蓝牙");
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.VISIBLE);
                btn3.setVisibility(View.VISIBLE);
                btnCancel = (TextView) choosePicDialog.findViewById(R.id.btnCancel);

                btn1.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        net_type = 1;
                        et_tcp.setText("串口");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });

                btn2.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        net_type = 2;
                        et_tcp.setText("红外");
//                        Toast.makeText(SetParaOneActivity.this,"选择2" ,Toast.LENGTH_SHORT).show();
                    }
                });

                btn3.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        net_type = 1;
                        et_tcp.setText("蓝牙");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });
                btnCancel.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                    }
                });

                choosePicDialog.setCancelable(true);
                choosePicDialog.show();

                break;

            case R.id.ll_para_3:


                choosePicDialog = new CustomDialog(SetParaTwoActivity.this, true);
                choosePicDialog.setCustomView(R.layout.pic_select_dlg);

                 window = choosePicDialog.getDialog().getWindow();
                window.setGravity(Gravity.BOTTOM);
                window.setLayout(AbsoluteLayout.LayoutParams.MATCH_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT);

                lyDlg = (LinearLayout) choosePicDialog.findViewById(R.id.dialog_layout);
                lyDlg.setPadding(0, 0, 0, 0);

                btn1 = (TextView) choosePicDialog.findViewById(R.id.btn1);
                btn2 = (TextView) choosePicDialog.findViewById(R.id.btn2);
                btn1.setText("奇偶校验");
                btn2.setText("CRC校验");
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.VISIBLE);
                btnCancel = (TextView) choosePicDialog.findViewById(R.id.btnCancel);

                btn1.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        sevice_type = 1;
                        et_zyfs.setText("奇偶校验");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });

                btn2.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        sevice_type = 2;
                        et_zyfs.setText("CRC校验");
//                        Toast.makeText(SetParaOneActivity.this,"选择2" ,Toast.LENGTH_SHORT).show();
                    }
                });
                btnCancel.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                    }
                });

                choosePicDialog.setCancelable(true);
                choosePicDialog.show();

                break;
            case R.id.tv_back:
                finish();
                break;
            case R.id.tv_save:
//                LoadingDialog loadingDialog =  new LoadingDialog(this);
//                loadingDialog.setMessage("正在加载...").show();
//                loadingDialog.dismiss();

                TopToastUtil.getInstance(this,R.layout.showdialog_err).showShortToast("123");

//                if("".equalsIgnoreCase(et_ip.getText().toString()))
//                {
//                    Toast.makeText(this,"请填写服务器ip",Toast.LENGTH_SHORT).show();
//                    return;
//                }
//                if("".equalsIgnoreCase(et_deveveid.getText().toString()))
//                {
//                    Toast.makeText(this,"请填写设备id",Toast.LENGTH_SHORT).show();
//                    return;
//                }
//                if("".equalsIgnoreCase(ed_msisdn.getText().toString()))
//                {
//                    Toast.makeText(this,"请填写设备msisdn",Toast.LENGTH_SHORT).show();
//                    return;
//                }

//                Consts.setServerIP(et_ip.getText().toString());
//                Consts.setdevice_id(et_deveveid.getText().toString());
//                Consts.setdevice_msisdn(ed_msisdn.getText().toString());

//                Toast.makeText(this,"设置完成",Toast.LENGTH_SHORT).show();

//                finish();
                break;
            case R.id.tv_set:

                    TopToastUtil.getInstance(this,R.layout.showdialog).showShortToast("保存成功");

                break;
            default:
                break;
        }


    }

}

